package Stringdemo;

import java.util.Scanner;

public class StringDemo9 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int money;
        while (true) {
            System.out.print("请输入金额：");
            money = sc.nextInt();
            if ( money >= 0 && money <= 9999999){
                break;
            }else {
                System.out.println("金额无效！！！");
            }
        }
        System.out.println(money);

        //转换后的整个数字串打印出来打印出来
        String moneyStr = "";
        while (true){
            int geWei = money % 10;
            String capitalGeWei = getCapitalNumber(geWei);
            moneyStr = capitalGeWei + moneyStr;
            money = money / 10;
            if (money == 0 ){
                break;
            }
        }

        //补零
        int count = 7 - moneyStr.length();
        for (int i = 0; i < count; i++) {
            moneyStr = "零" + moneyStr;
        }

        //添加单位
        String[] arr = {"佰","拾","万","仟","佰","拾","元"};
        String result = "";
        for (int i = 0; i < moneyStr.length(); i++) {
            char c = moneyStr.charAt(i);
            result = result + c + arr[i];
        }
        System.out.println(result);
    }

    //定义一个方法来讲小写数字转换成中文大写数字
    public static String getCapitalNumber(int number) {
        String[] arr = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        return arr[number];
    }
}
